﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Moving03.Administrator
{
    public partial class WebForm9 : System.Web.UI.Page
    {
        DataClasses1DataContext context = new DataClasses1DataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated == false || User.Identity.IsAuthenticated == true && !User.IsInRole("Admin"))
            {
                Response.Redirect("../Default.aspx");
            }
            int mavc =int.Parse(Request.QueryString["mavc"]);

            ThongTinVanChuyen ttvc = context.ThongTinVanChuyens.Single(p => p.Id_TTVC == mavc);
            
       
            DiaDiemCapNhat ddcn = context.DiaDiemCapNhats.Single(p => p.Id_ThongTinVanChuyen == mavc);
            var query = from dd in context.DuongDis
                        where dd.Id_DDCapNhat == ddcn.Id_DDCapNHat
                        select dd;
            foreach (var dd in query)
            {
                DuongDi duongdi = context.DuongDis.Single(p => p.Id_DuongDi == dd.Id_DuongDi);
                context.DuongDis.DeleteOnSubmit(duongdi);
            }
            context.DiaDiemCapNhats.DeleteOnSubmit(ddcn);
            context.ThongTinVanChuyens.DeleteOnSubmit(ttvc);

            NoiDi noiDi = context.NoiDis.Single(p => p.Id_Noidi == ttvc.IdNoiDi);
            context.NoiDis.DeleteOnSubmit(noiDi);

            NoiDen noiDen = context.NoiDens.Single(p => p.Id_NoiDen == ttvc.IdNoiden);
            context.NoiDens.DeleteOnSubmit(noiDen);
            context.SubmitChanges();
            Response.Redirect("CapNhatLH.aspx");
  
        }
    }
}